home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group00b.txt
/
000130_icon-group-sender_Mon Oct 30 16:27:22 2000.msg
< prev
next >
Wrap
Internet Message Format
|
2001-01-03
|
4KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id e9UNRBu14167
for icon-group-addresses; Mon, 30 Oct 2000 16:27:12 -0700 (MST)
Message-Id: <200010302327.e9UNRBu14167@baskerville.CS.Arizona.EDU>
Date: Mon, 30 Oct 2000 14:31:48 -0700
From: Steve Wampler <swampler@noao.edu>
X-Accept-Language: en
To: symbiot@my-deja.com
CC: icon-group@cs.arizona.edu
Subject: Re: How would the experts handle this...??
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 3009
symbiot@my-deja.com wrote:
>
> Greetings! And welcome to my latest edition of "Questions from the
> Newbie"
>
> The situation is this:
>
> I wish to scan thru a file and determine how letters "connect" with one
> another. By that I mean that for every letter of the alphabet, I would
> like to compile two lists: one containing all the letters which apper
> to the right of the given letter, and another for all those appearing
> to the left.
...
> Thus far, I have been roundly criticized by icon afficiandos for my use
> of explicit indexing. It seems to me an intuitive way to handle the
> problems I've faced and makes the program "readable" to the layman.
"layman"? As in someone who doesn't program? I'd claim that *any* solution
is unreadable in that case! If you mean someone who knows C and not Icon,
that may be right, but if that's your goal, then perhaps C would be a better
choice to start with?
> But, be that as it may, I'm curious as to how those "in the know" would
> handle this problem in a more "icon-esque" fashion.
Well, I took a few liberties:
(1) I assume the output could just as well show lowercase versions of
the letters for the "middle" letter instead of uppercase versions.
(2) and I assume you really mean "letters" and not "characters" (your
solution
also records non-letter characters on the left or right)
(3) and you don't want duplicated letters (your solution allows duplicated
letters, but I didn't read that as a requirement in the problem
statement)
(4) and, that the output should be formatted as shown in your
example (your code outputs it differently).
(5) the file name is given as a command line argument and all files named
on the command line should be processed and letter-pairs accumulated
across all the files (not file-by-file, which can be done by running
the program separately on each file).
Any of those is easy to change
Here's a solution:
global leftSides, rightSides
#
# Accumulate letter-pair information for all lines of all files listed on
# the command line.
#
procedure main(args)
leftSides := table('')
rightSides := table('')
every buildPairs(!open(!args))
showResults()
end
procedure buildPairs(s)
lChar := mChar := ''
every rChar := !s do {
# only remember pairs where left (or right) is a letter
#
leftSides[map(mChar)] ++:= (&letters ** lChar)
rightSides[map(mChar)] ++:= (&letters ** rChar)
# shift characters to the left...
#
# (aside: this also works!: rChar :=: mChar :=: lChar)
#
lChar := mChar
mChar := rChar
}
end
procedure showResults()
every c := !&lcase do {
# Could add test here to only print output that has left or right side
write(c,":\tleft- ",leftSides[c])
write( "\tright- ",rightSides[c])
}
end
--
Steve Wampler- SOLIS Project, National Solar Observatory
swampler@noao.edu